Repository navigation
A bulk write to an audited table is in the trail, row by row - #17
Merged
Merged
Conversation
- `removeBulk` and `updateBulk` sent a bare count (`deleteAndCount`,
`updateAndCount`). A count returns no rows, and the trail records a
write from the rows a statement returns, so a bulk delete or update,
soft or hard, left no row in the trail at all. On a recorded table they
now send `… RETURNING` and count the rows as they stream; the trail is
written right after the statement, as it is for an update by id.
- A `select` on `create`, `createBulk`, `update` or `upsert` narrowed the
RETURNING, so the trail saw only the selected columns, and nothing at
all when the id was not among them. On a recorded table the statement
now returns the whole row and the caller is handed only the select.
- Every other table keeps the bare count and the narrowed RETURNING.
`repositoriesFor` learns which tables are recorded from the relation
map `deriveDataLayer` returned, since that map is all a caller passes;
`audited` says it outright, and `audited: {}` keeps the count
everywhere.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
removeBulkandupdateBulksent a bare count (deleteAndCount,updateAndCount). A count goes through the runtime'sexecute, which returns no rows, soonRownever fires; the trail records a write from the rows a statement returns, so it recorded nothing. That held for soft deletes too, sincestampkeeps a statement's RETURNING and there was none to keep. On a recorded table both now send… RETURNINGand count the rows as they stream. The trail is written right after the statement, as it already is for an update by id.selecton a write could hide the row from the trail.create,createBulk,updateandupsertnarrowed RETURNING to the selected columns, so the trail kept only those, and nothing at all when the id was not among them. On a recorded table the statement now returns the whole row, and the caller is handed only what it selected.auditExcludekeeps the bare count and the narrowed RETURNING.repositoriesForlearns which tables are recorded from the relation mapderiveDataLayerreturned, because that map is all a caller passes today; the newauditedoption says it outright, andaudited: {}keeps the bare count everywhere, for a service with no trail.removeBulk(hard or soft)… RETURNING, one trail row per rowupdateBulk… RETURNING, one trail row per rowcreateBulk/create/update/upsertwith aselectUpserts were checked as well: they always returned their row, so the trail had one; it records an upsert that updated as an
INSERT, which is unchanged here.Tests
test/unit/repository.spec.tsnow builds its layer with the realauditmiddleware, its pool swapped for one that keeps what it inserts:DELETE … RETURNING, with aDELETEtrail row per row and the countUPDATE … SET "deletedAt" … RETURNING, recorded asDELETEper rowUPDATE … RETURNING, with anUPDATEtrail row per rowaudited: {}selectreturn the whole row to the trail and only the select to the callerSix of these fail on
master.npm test115/115,npm run lintandnpm run format:checkclean.Checked against a consuming service as well: its integration suite (175 tests) passes on this build, and removing a record through
removeBulknow leaves theDELETErow in its trail that 3.2.0 did not.